package com.gy.boot.common.check;

import com.gy.boot.common.util.BlankUtil;

public class CheckEntity {

    private String code; // 参数字段 code

    private String name; // 参数字段 name

    private CheckEnum checkEnum; // 校验字段: CheckEnum

    private Object checkValue; // 校验值: CheckEnum 常数值

    private String errMsg; // 错误消息

    public CheckEntity() {}

    public CheckEntity(String code, CheckEnum checkEnum) {
        this.code = code;
        this.checkEnum = checkEnum;
    }

    public CheckEntity(String code, CheckEnum checkEnum, Object checkValue) {
        this.code = code;
        this.checkEnum = checkEnum;
        this.checkValue = checkValue;
    }

    public CheckEntity(String code, String name, CheckEnum checkEnum) {
        this.code = code;
        this.name = name;
        this.checkEnum = checkEnum;
    }

    public CheckEntity(String code, String name, CheckEnum checkEnum, Object checkValue) {
        this.code = code;
        this.name = name;
        this.checkEnum = checkEnum;
        this.checkValue = checkValue;
    }

    public CheckEntity(String code, CheckEnum checkEnum, String errMsg) {
        this.code = code;
        this.checkEnum = checkEnum;
        this.errMsg = errMsg;
    }

    public CheckEntity(String code, CheckEnum checkEnum, Object checkValue, String errMsg) {
        this.code = code;
        this.checkEnum = checkEnum;
        this.checkValue = checkValue;
        this.errMsg = errMsg;
    }

    public CheckEntity(String code, String name, CheckEnum checkEnum, String errMsg) {
        this.code = code;
        this.name = name;
        this.checkEnum = checkEnum;
        this.errMsg = errMsg;
    }

    public CheckEntity(String code, String name, CheckEnum checkEnum, Object checkValue, String errMsg) {
        this.code = code;
        this.name = name;
        this.checkEnum = checkEnum;
        this.checkValue = checkValue;
        this.errMsg = errMsg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public CheckEntity setName(String name) {
        this.name = name;
        return this;
    }

    public CheckEnum getCheckEnum() {
        return checkEnum;
    }

    public void setCheckEnum(CheckEnum checkEnum) {
        this.checkEnum = checkEnum;
    }

    public Object getCheckValue() {
        return checkValue;
    }

    public void setCheckValue(String checkValue) {
        this.checkValue = checkValue;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public CheckEntity setErrMsg(String errMsg) {
        this.errMsg = errMsg;
        return this;
    }

    public String getErrMsg(String defaultMsg) {
        if (!BlankUtil.isBlank(this.errMsg)) {
            return this.errMsg;
        }
        return (BlankUtil.isBlank(this.name) ? "参数"+this.code : this.name) + defaultMsg;
    }

    public Double getCheckValueDouble() {
        if (this.checkValue == null) {
            return null;
        }
        try {
            return Double.parseDouble(this.checkValue.toString());
        } catch (Exception e) {
            return null;
        }
    }

    public Integer getCheckValueInt() {
        if (this.checkValue == null) {
            return null;
        }
        try {
            return Integer.parseInt(this.checkValue.toString());
        } catch (Exception e) {
            return null;
        }
    }

    public String getCheckValueStr() {
        if (this.checkValue == null) {
            return null;
        }
        return this.checkValue.toString();
    }

    public String[] getCheckValueArr() {
        if (this.checkValue == null) {
            return null;
        }
        try {
            return (String[]) this.checkValue;
        } catch (Exception e) {
            return null;
        }
    }

}
